const queue = new Set()
const p = Promise.resolve()
let isFlushing = false
export function queueJob(job){
  queue.add(job)
  if(!isFlushing) {
    p.then(()=>{
      try {
        queue.forEach(job=> job())
      } finally {
        isFlushing = false
        queue.clear = 0
      }
    })
    isFlushing = true
  }
}